<!--

/*
* Copyright (C) 2005-2013 University of Sydney
*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/**
* brief description of file
*
* @author      Tom Murtagh
* @author      Kim Jackson
* @author      Ian Johnson   <ian.johnson@sydney.edu.au>
* @author      Stephen White   <stephen.white@sydney.edu.au>
* @author      Artem Osmakov   <artem.osmakov@sydney.edu.au>
* @copyright   (C) 2005-2013 University of Sydney
* @link        http://Sydney.edu.au/Heurist
* @version     3.1.0
* @license     http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @package     Heurist academic knowledge management system
* @subpackage  !!!subpackagename for file such as Administration, Search, Edit, Application, Library
*/

-->
<!--

/**
 * editPreferences.html, edits display preferences
 *
 * @copyright (C) 2005-2010 University of Sydney Digital Innovation Unit.
 * @link: http://HeuristScholar.org
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
 * @package Heurist academic knowledge management system
 * @todo
 **/

-->
<html>
<head>
  <title>My Profile. Preferences</title>
	<link rel=stylesheet href="../../common/css/global.css">
	<link rel=stylesheet href="../../common/css/edit.css">
	<link rel=stylesheet href="../../common/css/admin.css">
	<style>
	.input-row, .input-row .input-header-cell, .input-row div.input-cell {vertical-align:middle}
    .input-header-cell{
        width:250px !important;
    }
    h3{
        width: 200px;
        padding: 0px;
        text-align: right;
    }
	</style>

</head>

<body class="popup" onLoad="showPreferences()" width="640" height="640">

  <script src="../../common/js/utilsLoad.js"></script>
  <script>

	var mybkm, agg, navi, favsrch;

	function showPreferences() {
		document.getElementById("results-per-page").value
			= top.HEURIST.util.getDisplayPreference("results-per-page");
		document.getElementById("defaultSearch").value
			= top.HEURIST.util.getDisplayPreference("defaultSearch");
		document.getElementById("favourites").value
			= top.HEURIST.util.getDisplayPreference("favourites");
		// document.getElementById("loadRelatedOnSearch").value
			// = top.HEURIST.util.getDisplayPreference("loadRelatedOnSearch");
		var rel = top.HEURIST.util.getDisplayPreference("loadRelatedOnSearch");
		document.getElementById("loadRelatedOnSearch").checked
			= (rel==='true');
		var rec = top.HEURIST.util.getDisplayPreference("defaultRecentPointerSearch"); // pointer field editing
		document.getElementById("defaultRecentPointerSearch").checked
			= (rec==='true');
		var bkm = top.HEURIST.util.getDisplayPreference("defaultMyBookmarksSearch"); // main search default on [enter]
		document.getElementById("defaultMyBookmarksSearch").checked
			= (bkm==='true');
        mybkm = top.HEURIST.util.getDisplayPreference("showMyBookmarks");
        document.getElementById("showMyBookmarks").checked = (mybkm!=='false');
		var asr = top.HEURIST.util.getDisplayPreference("autoSelectRelated"); // auto select related records (one level for now)
		document.getElementById("autoSelectRelated").checked
			= (asr!=='false');
		var adl = top.HEURIST.util.getDisplayPreference("autoDeselectOtherLevels"); // main search default on [enter]
		document.getElementById("autoDeselectOtherLevels").checked
			= (adl!=='false');

        var ptd = top.HEURIST.util.getDisplayPreference("tagging-popup");
        document.getElementById("promptTagOnDataAddition").checked = (ptd!=='false');

        agg = top.HEURIST.util.getDisplayPreference("showAggregations");
        document.getElementById("showAggregations").checked = (agg!=='false');

        navi = top.HEURIST.util.getDisplayPreference("showNavMenuAlways");
        document.getElementById("showNavMenuAlways").checked = (navi!=='false');

        favsrch = top.HEURIST.util.getDisplayPreference("showFavouritesSearch");
        document.getElementById("showFavouritesSearch").checked = (favsrch!=='false');

		var mol = top.HEURIST.util.getDisplayPreference("report-output-limit");
		if(isNaN(mol) || parseInt(mol)<1) mol = 1000;
		document.getElementById("report-output-limit").value = mol;

		var showquery = top.HEURIST.util.getDisplayPreference("searchQueryInBrowser");
        document.getElementById("showSearchQueryInBrowser").checked = (showquery!=='false');
	}

	function save() {
		var reload_nav = false;
		var reload_menu = false;

		var rpp = parseInt(document.getElementById("results-per-page").value);
		var def = document.getElementById("defaultSearch").value;
		var fav = document.getElementById("favourites").value;
		var rel = (document.getElementById("loadRelatedOnSearch").checked)?'true':'false';
		var rec = (document.getElementById("defaultRecentPointerSearch").checked)?'true':'false';
		var bkm = (document.getElementById("defaultMyBookmarksSearch").checked)?'true':'false';
		var asr = (document.getElementById("autoSelectRelated").checked)?'true':'false';
		var adl = (document.getElementById("autoDeselectOtherLevels").checked)?'true':'false';
        var ptd = (document.getElementById("promptTagOnDataAddition").checked)?'true':'false';
        var showquery = (document.getElementById("showSearchQueryInBrowser").checked)?'true':'false';


		if (isNaN(rpp) || rpp < 1 || rpp > 500) {
			alert("Results per page must be between 1 and 500");
			return;
		}

		var mol = parseInt(document.getElementById("report-output-limit").value);
		if (isNaN(mol) || mol<rpp){
			alert("'Limit for report output' must be equal or more than 'Results per page'");
			return;
		}
		if(mol>5000){
			if(! confirm("Large limit for report output may delay map rendereing and smarty processing. Do you confirm?") ){
				return;
			}
		}

		var new_val = (document.getElementById("showMyBookmarks").checked)?'true':'false';
        if(mybkm != new_val){
        	reload_nav = true;
        	mybkm = new_val;
		}
        new_val = (document.getElementById("showAggregations").checked)?'true':'false';
        if(agg != new_val){
        	reload_nav = true;
        	agg = new_val;
		}
        new_val = (document.getElementById("showNavMenuAlways").checked)?'true':'false';
        if(navi != new_val){
        	reload_menu = true;
        	navi = new_val;
		}
        new_val = (document.getElementById("showFavouritesSearch").checked)?'true':'false';
        if(favsrch != new_val){
        	reload_nav = true;
        	favsrch = new_val;
		}

		top.HEURIST.util.setDisplayPreference(["results-per-page",
		"defaultSearch",
		"favourites",
		"loadRelatedOnSearch",
		"defaultRecentPointerSearch",
		"defaultMyBookmarksSearch",
		"showMyBookmarks",
		"autoSelectRelated",
		"autoDeselectOtherLevels",
		"tagging-popup",
		"showAggregations",
		"showNavMenuAlways",
		"showFavouritesSearch",
		"report-output-limit",
		"searchQueryInBrowser"],
		[rpp,def,fav,rel,rec,bkm,mybkm,asr,adl,ptd,agg,navi,favsrch,mol,showquery]);

		/*
		top.HEURIST.util.setDisplayPreference("defaultSearch", def);
		top.HEURIST.util.setDisplayPreference("favourites", fav);
		top.HEURIST.util.setDisplayPreference("loadRelatedOnSearch", rel);
		top.HEURIST.util.setDisplayPreference("defaultRecentPointerSearch", rec);
        top.HEURIST.util.setDisplayPreference("defaultMyBookmarksSearch", bkm);
        top.HEURIST.util.setDisplayPreference("showMyBookmarks", mybkm);
		top.HEURIST.util.setDisplayPreference("autoSelectRelated", asr);
		top.HEURIST.util.setDisplayPreference("autoDeselectOtherLevels", adl);
		top.HEURIST.util.setDisplayPreference("tagging-popup", ptd);
        top.HEURIST.util.setDisplayPreference("showAggregations", agg);
        top.HEURIST.util.setDisplayPreference("showNavMenuAlways", navi);
        top.HEURIST.util.setDisplayPreference("showFavouritesSearch", favsrch);
        top.HEURIST.util.setDisplayPreference("report-output-limit", mol);
        top.HEURIST.util.setDisplayPreference("searchQueryInBrowser", showquery);
        */

		//update underlaying search UI
		if(top.HEURIST.search){
			if(reload_nav){
				top.HEURIST.search.show_hideItemsInNavigation();
			}
			if(reload_menu){
				top.HEURIST.search.show_hideNavigationMenu();
			}

		}
		window.close();
	}
  </script>

  <!-- h2>My Profile Preferences</h2 -->


   <div class="input-row">
	<div class="input-header-cell">Search results per page (20 - 500)</div><div  class="input-cell"><input id="results-per-page"></div>
   </div>
   <div class="input-row">
	<div class="input-header-cell">Limit number of lines in report output (no warning if limit exceeded)</div><div  class="input-cell"><input id="report-output-limit"></div>
   </div>
   <div class="input-row">
	<div class="input-header-cell">Heurist search string to execute when loading the search page<br> for example, tag:Favourites</div><div  class="input-cell"><input id="defaultSearch">
	<br><input type="checkbox" id="defaultMyBookmarksSearch" style="vertical-align:middle">Search MyBookmarks only
<!--	<br><input type="radio" name="defaultMyBookmarksSearch" value="myBookmarks">My Bookmarks
	<br><input type="radio" name="defaultMyBookmarksSearch" value="allBookmarks">All Bookmarks-->
	</div>
   </div>
   <div class="input-row">
	<div class="input-header-cell">How do you spell Favourites/Favorites?</div><div  class="input-cell"><input id="favourites"></div>
   </div>
   <h3>Search</h3>
   <div class="input-row">
    <div class="input-header-cell">Show current search query in browser search field</div><div  class="input-cell"><input type="checkbox" id="showSearchQueryInBrowser"></div>
    <div class="input-header-cell">Show Favourites link in search screen navigation panel</div><div  class="input-cell"><input type="checkbox" id="showFavouritesSearch"></div>
  </div>
   <div class="input-row">
    <div class="input-header-cell">Show Aggregations link in search screen navigation panel</div><div  class="input-cell"><input type="checkbox" id="showAggregations"></div>
    <div class="input-header-cell">Show My Bookmarks section in the search screen navigation panel</div><div  class="input-cell"><input type="checkbox" id="showMyBookmarks"></div>
  </div>
  <div class="input-row">
    <div class="input-header-cell">Show Navigation menu in search screen even when navigation panel is open</div><div  class="input-cell"><input type="checkbox" id="showNavMenuAlways"></div>
  </div>

  <h3>Relationships</h3>
  <div class="input-row">
    <div class="input-header-cell">Load related records below search<br/>(leave off if not required)</div><div class="input-cell"><input type="checkbox" id="loadRelatedOnSearch"></div>
  </div>
  <div class="input-row">
    <div class="input-header-cell">Automatically select related records</div><div  class="input-cell"><input type="checkbox" id="autoSelectRelated"></div>
    <div class="input-header-cell">Automatically deselect when changing active level in search</div><div  class="input-cell"><input type="checkbox" id="autoDeselectOtherLevels"></div>
  </div>

  <h3>Editing</h3>
  <div class="input-row">
    <div class="input-header-cell">When exiting record edit, prompt for tags if no tags have been set</div><div  class="input-cell"><input type="checkbox" id="promptTagOnDataAddition"></div>
	<div class="input-header-cell">When entering a pointer field in record edit, default to recent records search (otherwise All Records)</div><div  class="input-cell"><input type="checkbox" id="defaultRecentPointerSearch"></div>
  </div>

  <div id="buttons" class="actionButtons">
   <input type="button" value="save" onClick="save();">
   <input type="button" value="cancel" onClick="window.close();">
  </div>

  <p><hr>Use the link below to add a bookmarklet to your browser toolbar. The bookmarklet captures highlighted
  <br>text from a web page and creates an Internet Bookmark record, extracting certain fields (DOI, ISBN, ISSN etc.). </p>
  <i>Drag this link to your bookmarks bar:</i> &nbsp;&nbsp;

  <script>
    var hBase = (top.HEURIST && top.HEURIST.baseURL)? top.HEURIST.baseURL
    			: document.location.href.replace(/admin\/.*/,"");
    var database = location.search.match(/db=([^&]+)/) ? location.search.match(/db=([^&]+)/)[1]:"";

    var bookmarkletname = top.HEURIST.VERSION;

    var html = "<a id=\"bookmarklet-link\" onclick=\"alert('Heurist Bookmarklet: drag this link to your browser bookmarks toolbar, or right-click the link, choose Bookmark This Link, and add the link to your Bookmarks Toolbar or Favorites.');return false;\" title=\"Heurist Bookmarklet. Drag this link to your browser bookmarks toolbar, or right-click the link,"
    + " choose Bookmark This Link, and add the link to your Bookmarks Toolbar or Favorites.\""
    + " href=\"javascript:(function(){h='" + hBase + "';"
    + "d=document;c=d.contentType;"
    + "if(c=='text/html'||!c){"
    + "if(d.getElementById('__heurist_bookmarklet_div'))return%20Heurist.init();"
    + "s=d.createElement('script');s.type='text/javascript';"
    + "s.src=h+'import/bookmarklet/bookmarkletPopup.php?db="+database+"';"
    + "d.getElementsByTagName('head')[0].appendChild(s);}"
    + "else{e=encodeURIComponent;w=open(h+'records/add/addRecordPopup.php?db="+database+"&t='+e(d.title)+'&u='+e(location.href));"
    + "window.setTimeout('w.focus()',200);}"
    + "})();\"><b>>> "+database+" </b></a>";
    document.write(html);
</script>

Note: this bookmarklet not yet debugged
 </body>
</html>

